﻿<Window x:Class="ShaderPad.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ShaderPad"
    Title="ShaderPad" Height="600" Width="800" Icon="/ShaderPad;component/images/splogox.ico">
    <Window.Resources>
        <LinearGradientBrush x:Key="BarBGBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF000000" Offset="0.36"/>
            <GradientStop Color="#FF070F3F" Offset="1"/>
            <GradientStop Color="#FF3D3D3D" Offset="0.338"/>
            <GradientStop Color="#FF6871A2" Offset="0"/>
        </LinearGradientBrush>
    </Window.Resources>
    <DockPanel Background="Black">
        <Grid DockPanel.Dock="Top" MinHeight="20" >
            <ToolBar Background="{DynamicResource BarBGBrush}" Foreground="AliceBlue">
                <Button x:Name="btnOptions" Foreground="#FFC7C7C7" Click="btnOptions_Click">
                    <Image Source="images\Tools.png" Height="16"/>
                    <Button.ToolTip>ShaderPad Options</Button.ToolTip>
                </Button>
                <ToggleButton x:Name="autoParse" Foreground="#FFC7C7C7" Click="autoParse_Click" FontWeight="Normal">
                    <Image Source="images\AutoRefresh.png" Height="16"/>
                    <ToggleButton.ToolTip>Auto Refresh PreView from XAML</ToggleButton.ToolTip>
                </ToggleButton>
                <Button x:Name="btnRefresh" Foreground="#FFC7C7C7" Click="btnRefresh_Click">
                    <Image Source="images\Refresh.png" Height="16"/>
                    <Button.ToolTip>Refresh PreView from XAML</Button.ToolTip>
                </Button>
                <Button ToolTip="Zoom out">
                    <Image Source="images\ZoomOut.png" Height="16"/>
                </Button>
                <Slider Width="180.8" Minimum="0.01" Value="{Binding ZoomFactor}" Cursor="Hand" AutoToolTipPlacement="BottomRight" ValueChanged="Slider_ValueChanged" Style="{DynamicResource ZoomSliderStyle}" />
                <Button ToolTip="Zoom in">
                    <Image Source="images\ZoomIn.png" Height="16"/>
                </Button>
                <TextBox Width="60" Text="{Binding ZoomFactor, StringFormat=P}"/>
            </ToolBar>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="20"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border ClipToBounds="True">
                <Canvas x:Name="canvas" ClipToBounds="True" Background="Black" >
                    <Border x:Name="preView" BorderBrush="White" BorderThickness="1" Background="Transparent"
                            PreviewMouseLeftButtonDown="preView_PreviewMouseLeftButtonDown"
                            PreviewMouseLeftButtonUp="preView_PreviewMouseLeftButtonUp" PreviewMouseMove="preView_PreviewMouseMove"
                            Canvas.Left="0" Canvas.Top="0">
                        <Border.RenderTransform>
                            <ScaleTransform ScaleX="{Binding ZoomFactor}" ScaleY="{Binding ZoomFactor}"/>
                        </Border.RenderTransform>
                    </Border>
                </Canvas>
            </Border>
            <TextBox x:Name="txtXAML" Grid.Column="0" Grid.Row="1" AcceptsReturn="True" AcceptsTab="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" xml:space="preserve" Background="#FFFFFFFF">  
            </TextBox>
            <GridSplitter Grid.RowSpan="2" VerticalAlignment="Stretch" Grid.Column="0" HorizontalAlignment="Right" Width="5" ResizeDirection="Columns" ShowsPreview="True" >
                <GridSplitter.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="#FF000000" Offset="0.36"/>
                        <GradientStop Color="#FF070F3F" Offset="1"/>
                        <GradientStop Color="#FF3D3D3D" Offset="0.338"/>
                        <GradientStop Color="#FF6871A2" Offset="0"/>
                    </LinearGradientBrush>
                </GridSplitter.Background>
            </GridSplitter>
            <DockPanel Grid.Column="1" Grid.Row="1" >
                <ToolBar DockPanel.Dock="Top" Height="26" Background="{DynamicResource BarBGBrush}">
                    <Button ToolTip="Open PixelShader from local disk" x:Name="btnLoadShader" Click="btnLoadShader_Click">
                    	<Image Source="images/OpenFolder.ico" Width="15" Height="15"/>
                    </Button>
                    <Button ToolTip="Save PixelShader to local disk" x:Name="btnSaveShader" Click="btnSaveShader_Click">
                        <Image Source="images/Save.ico" Width="15" Height="15"/>
                    </Button>
                    <Button ToolTip="Open PixelShader from Web" x:Name="btnLoadShaderFromWeb" Click="btnLoadShaderFromWeb_Click">
                        <Image Source="images/webfolder.ico" Width="15" Height="15"/>
                    </Button>
                    <Button ToolTip="Save PixelShader to Web" x:Name="btnSaveShaderToWeb" Click="btnSaveShaderToWeb_Click">
                        <Image Source="images/Globe.ico" Width="15" Height="15"/>
                    </Button>
                    <TextBlock x:Name="txtEfectName" Margin="14,2,0,0" Text="NewEffect.fx" Foreground="WhiteSmoke" HorizontalAlignment="Right"/>
                </ToolBar>
                <Button DockPanel.Dock="Bottom" x:Name="btnCompile" Click="btnCompile_Click" ToolTip="Complie the PixelShader and apply it to the preview">
                    <StackPanel Orientation="Horizontal" >
                        <Image Source="images/directx.ico" Height="16" Margin="2"/>
                        <TextBlock Text="Compile" Margin="2"/>
                    </StackPanel>
                </Button>

                <TextBox x:Name="txtPixelShader" AcceptsReturn="True" AcceptsTab="True" xml:space="preserve" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">sampler2D input : register(s0);   
float val0 : register(c0);
float val1 : register(c1);
float4 main(float2 uv : TEXCOORD) : COLOR
{      
    float4 Color;
    float4 clr;
    Color= tex2D( input , uv.xy);
    clr=Color;
    if (uv.x &lt; 0.5 &amp;&amp; uv.y &lt; 0.5)
    {
        Color.r = clr.b;
        Color.g = clr.r;
        Color.b = clr.g;
    }
    else if (uv.y &lt; 0.5)
    {
        Color.r = clr.g*(1-val0);
        Color.g = clr.b;
        Color.b = clr.r;
    }
    else if (uv.x &lt; 0.5)
    {
        Color.r = clr.g;
        Color.g = clr.b;
        Color.b = val1 * clr.r;
    }
    else
    {
    Color.rgb=1-Color.rgb;
    }
    return Color;             
}
                </TextBox>
            </DockPanel>
            <Border x:Name="controls" Grid.Column="1" Grid.Row="0">
                <DockPanel>
                    <DockPanel DockPanel.Dock="Top" >
                        <TextBlock Width="Auto" Height="Auto" Margin="2,2,2,2" Foreground="#FFD3D3D3"><Run Text="Apply to:"/></TextBlock>
                        <local:TVComboControl x:Name="elementTree" Width="Auto" Height="Auto" Margin="2,2,2,2" />
                    </DockPanel>
                    <ListView x:Name="lvShaderTextures" DockPanel.Dock="Top" Height="100">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="sampler" DisplayMemberBinding="{Binding Path=Name}" Width="50"/>
                                <GridViewColumn Header="value">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                                <Rectangle Width="100" Height="30" Fill="{Binding Path=Texture}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="" >
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Button Tag="{Binding}" Click="ChangeTexture_Click">Change</Button>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <ListView x:Name="lvShaderInputs">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="var" DisplayMemberBinding="{Binding Path=Name}" Width="50"/>
                                <GridViewColumn Header="Min">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Text="{Binding Path=MinValue}" Width="50" HorizontalContentAlignment="Right"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="value">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <DockPanel>
                                                <Slider DockPanel.Dock="Bottom" Value="{Binding Path=Value}" Width="100"
                                                        Maximum="{Binding Path=MaxValue}" Minimum="{Binding Path=MinValue}"/>
                                                <TextBox Text="{Binding Path=Value}" HorizontalContentAlignment="Right"/>
                                            </DockPanel>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="Max" >
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Text="{Binding Path=MaxValue}" Width="50" HorizontalContentAlignment="Right"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="Animate" >
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>                                            
                                            <CheckBox Tag="{Binding}" Click="CheckBox_Click" ></CheckBox>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="AutoReverse" >
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <CheckBox x:Name="chkAutoReverse" Tag="{Binding}" Click="chkAutoReverse_Click"></CheckBox>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                </DockPanel>
            </Border>
            <Border x:Name="output" Grid.Row="2" Grid.ColumnSpan="2"  Height="10">
                <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="txtOutput" Foreground="#FFFD0000"></TextBlock>
            </Border>
            <Border x:Name="status" Grid.Row="3" Grid.ColumnSpan="2" Background="{DynamicResource BarBGBrush}">
                <Grid/>
            </Border>
            <GridSplitter Grid.ColumnSpan="2" VerticalAlignment="Bottom" Grid.Row="0" HorizontalAlignment="Stretch" Height="5" ResizeDirection="Rows" ResizeBehavior="BasedOnAlignment" ShowsPreview="True" Background="{DynamicResource BarBGBrush}" />
        </Grid>
    </DockPanel>
</Window>
